/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.mailfolder;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.mailfolder.Mailfolder;

/**
 * @author Administrator (email:xxh@163.com)
 * @since 2013-02-21
 */
@Service("mailfolderService")
public class MailfolderServiceImpl implements MailfolderService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of Mailfolder
     ****************************************/
    public void insert(Mailfolder mailfolder) throws Exception {
        mailfolder.setFolderid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(mailfolder);
    }

    /****************************************
     * Update a instace of Mailfolder
     ****************************************/
    public void update(Mailfolder mailfolder) throws Exception {
        iDataSet4iBatis.update(mailfolder);
    }

    /****************************************
     * Delete a instace of Mailfolder
     ****************************************/
    public void delete(Mailfolder mailfolder) throws Exception {
        iDataSet4iBatis.delete(mailfolder);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(Mailfolder mailfolder) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(Mailfolder mailfolder) throws Exception {
        String statementId = mailfolder.getStatmentId();
        String mainId = mailfolder.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> mailfolderList = new ArrayList<BaseModel>();
        for (String id : ids) {
            Mailfolder model = new Mailfolder();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            mailfolderList.add(model);
        }
        iDataSet4iBatis.batchDelete(mailfolderList);
    }

    /****************************************
     * Query instaces of Mailfolder
     ****************************************/
    public List<BaseModel> queryAsList(Mailfolder mailfolder) throws Exception {
        String queryListStatement = "";
        if (mailfolder.isPaging()) {
            queryListStatement = mailfolder.getStatmentId();
            mailfolder.setStatmentId("Mailfolder.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(mailfolder);
            mailfolder.setTotalCount(baseModel.getTotalCount());
            mailfolder.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(mailfolder);
    }

    /****************************************
     * Query a instaces of Mailfolder
     ****************************************/
    public BaseModel queryAsObject(Mailfolder mailfolder) throws Exception {
        return iDataSet4iBatis.queryAsObject(mailfolder);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
